package com.yunfei.yunmusic.web.control;

import com.yunfei.yunmusic.web.model.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class CommentLikeControl {
    @Autowired
    private CommentPostControl commentPostControl;
    @ResponseBody
    @RequestMapping(path="/comment/like")
    public Comment like(@RequestParam(value="songId") String songId,  String commentId){
             List<Comment> commentList=commentPostControl.getComments(songId);
             Comment result=null;
             for( Comment comment: commentList){
                if(!comment.getId().equals(commentId)){
                    continue;
                }
                 comment.setLikeNum(comment.getLikeNum()+1);
                 result=comment;
             }
             return result;
    }
}
